<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入搜索内容" />

    <script>
        // 获取元素
        var oInput = document.querySelector("input");

        oInput.onkeyup = throttle(getData, 700);
        // 节流
        function getData() {
            console.log(oInput.value);
            console.log("调用后台数据");
        }

        function throttle(fn, delay) {
            // 记录激活状态
            var flag = true;
            return function() {
                if (!flag) { //未激活状态
                    return false;
                }
                flag = false;
                setTimeout(function() {
                    fn();
                    flag = true;
                }, delay);

            }
        }
    </script>

</body>

</html>